/*
 * Copyright 2012 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package com.jobs.dal;

import org.springframework.orm.ibatis.SqlMapClientOperations;

/**
 * DAO基础类
 * 
 * @author jiansheng.xujs 2012-3-27 下午9:46:39
 */
public class BaseDao<T> {

    protected SqlMapClientOperations sqlMapClientTemplate;
    protected String                 namespace;

    @SuppressWarnings("unchecked")
    protected T load(Long id, String className) {
        return (T) sqlMapClientTemplate.queryForObject(namespace + "." + "load", id);
    }

    public boolean update(T entity) {
        return sqlMapClientTemplate.update(namespace + "." + "update", entity) == 1;
    }

    public void create(T entity) {
        sqlMapClientTemplate.insert(namespace + "." + "create", entity);
    }

    public void delete(Long id) {
        sqlMapClientTemplate.delete(namespace + "." + "delete", id);
    }

    public void setSqlMapClientTemplate(SqlMapClientOperations sqlMapClientTemplate) {
        this.sqlMapClientTemplate = sqlMapClientTemplate;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

}
